import java.util.Arrays;

public class Solution1444 {
    public int ways(String[] pizza, int k) {
        int[][][] f=new int[pizza.length][pizza[0].length()][k+1];
        for (int i=0;i<pizza.length;i++){
            for (int j=0;j<pizza[0].length();j++){
                Arrays.fill(f[i][j],-1);
            }
        }
        return dfs(pizza,f,0,0,k-1);
    }

    private int dfs(String[] pizza, int[][][] f, int x, int y, int k) {
        if (f[x][y][k]==-1){
            if (k==0){
                boolean flag=false;
                for (int i=x;i<pizza.length;i++){
                    for (int j=y;j<pizza[0].length();j++){
                        if (pizza[i].charAt(j)=='A'){
                            flag=true;
                            break;
                        }
                    }
                }
                f[x][y][0]=flag?1:0;
            }else {
                f[x][y][k]=0;
                int xStart=-1;
                for (int i=x;i<pizza.length;i++){
                    for (int j=y;j<pizza[0].length();j++){
                        if (pizza[i].charAt(j)=='A'){
                            xStart=i;
                            break;
                        }
                    }
                    if (xStart!=-1){
                        break;
                    }
                }
                if (xStart!=-1){
                    for (int i=xStart+1;i<pizza.length;i++){
                        f[x][y][k]=(f[x][y][k]+dfs(pizza,f,i,y,k-1))%1000000007;
                    }
                }
                int yStart=-1;
                for (int i=y;i<pizza[0].length();i++){
                    for (int j=x;j<pizza.length;j++){
                        if (pizza[j].charAt(i)=='A'){
                            yStart=i;
                            break;
                        }
                    }
                    if (yStart!=-1){
                        break;
                    }
                }
                if (yStart!=-1){
                    for (int i=yStart+1;i<pizza[0].length();i++){
                        f[x][y][k]=(f[x][y][k]+dfs(pizza,f,x,i,k-1))%1000000007;
                    }
                }
            }
        }
        return f[x][y][k];
    }

    public static void main(String[] args) {
        System.out.println(new Solution1444().ways(new String[]{"A..","AAA","..."},3));
    }
}
